package com.icongyou.enterprise.talent_profile.controller;

import com.icongyou.enterprise.common.result.PageResult;
import com.icongyou.enterprise.common.result.Result;
import com.icongyou.enterprise.data_aggregation.entity.vo.StudentTopSubmissionDetailVO;
import com.icongyou.enterprise.data_aggregation.entity.vo.StudentTopSubmissionSimpleVO;
import com.icongyou.enterprise.talent_profile.entity.vo.*;
import com.icongyou.enterprise.talent_profile.service.ProfileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/profile")
@RequiredArgsConstructor
public class ProfileController {

    private final ProfileService talentProfileService;

    /**
     * 1. 获取学生基础档案信息
     */
    @GetMapping("/{studentId}/basic")
    public Result<StudentBasicVO> getStudentBasicInfo(@PathVariable String studentId) {
        try {
            StudentBasicVO basicInfo = talentProfileService.getStudentBasicInfo(studentId);
            return Result.success(basicInfo);
        } catch (Exception e) {
            return Result.error("获取学生信息失败");
        }
    }

    /**
     * 2. 获取学生学习情况概览
     */
    @GetMapping("/{studentId}/learning-overview")
    public Result<LearningOverviewRespVO> getLearningOverview(
            @PathVariable String studentId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        try {
            LearningOverviewRespVO overview = talentProfileService.getLearningOverview(studentId, page, size);
            return Result.success(overview);
        } catch (Exception e) {
            return Result.error("获取学习概览失败");
        }
    }

    /**
     * 3. 获取学生选修的所有课程信息
     */
    @GetMapping("/{studentId}/courses")
    public Result<List<StudentCourseVO>> getStudentCourses(@PathVariable String studentId) {
        try {
            List<StudentCourseVO> courses = talentProfileService.getStudentCourses(studentId);
            return Result.success(courses);
        } catch (Exception e) {
            return Result.error("获取课程列表失败");
        }
    }

    /**
     * 获取学生核心成果简版列表（首页展示）
     */
    @GetMapping("/{studentId}/top-submissions/simple")
    public Result<List<StudentTopSubmissionSimpleVO>> getTopSubmissionsSimple(@PathVariable String studentId) {
        List<StudentTopSubmissionSimpleVO> result = talentProfileService.getStudentTopSubmissionsSimple(studentId);
        return Result.success(result);
    }

    /**
     * 获取学生核心成果详情列表（详情页展示）
     */
    @GetMapping("/{studentId}/top-submissions/detail")
    public Result<List<StudentTopSubmissionDetailVO>> getTopSubmissionsDetail(@PathVariable String studentId) {
        List<StudentTopSubmissionDetailVO> result = talentProfileService.getStudentTopSubmissionsDetail(studentId);
        return Result.success(result);
    }

    /**
     * 根据提交ID获取单个提交的详细内容
     */
    @GetMapping("/submissions/{submissionId}")
    public Result<SubmissionDetailVO> getSubmissionDetail(@PathVariable String submissionId) {
        SubmissionDetailVO result = talentProfileService.getSubmissionDetailById(submissionId);
        return Result.success(result);
    }

    /**
     * 获取学生在指定课程中得分最高的提交
     */
    @GetMapping("/{studentId}/course/{courseId}/top-submission")
    public Result<CourseTopSubmissionVO> getTopSubmissionByStudentAndCourse(
            @PathVariable String studentId,
            @PathVariable String courseId) {
        try {
            CourseTopSubmissionVO topSubmission = talentProfileService.getTopSubmissionByStudentAndCourse(studentId, courseId);
            return Result.success(topSubmission);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
